package com.r2coding.system.service.impl;

import com.r2coding.system.dao.UserDao;
import com.r2coding.system.feign.ArticleFeignService;
import com.r2coding.system.feign.MusicFeignService;
import com.r2coding.system.service.IndexService;
import com.r2coding.system.vo.resp.DataCountRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author:98k灬
 * @since:2022/06/04 12:07
 **/
@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    UserDao userDao;

    @Autowired
    MusicFeignService musicFeignService;

    @Autowired
    ArticleFeignService articleFeignService;

    @Cacheable(value = "dataCountRespVo", key = " 'INDEX_INFO' ")
    @Override
    public DataCountRespVo getDataCount() {
        DataCountRespVo vo = new DataCountRespVo();
        // 获取用户数
        Integer userCount = userDao.selectCount(null);
        vo.setUserCount(userCount);
        // 获取文章数
        Integer articleCount = articleFeignService.getArticleCount();
        vo.setArticleCount(articleCount);
        // 获取音乐数
        Integer songCount = musicFeignService.getSongCount();
        vo.setMusicCount(songCount);
        // 获取留言数
        Integer messageCount = articleFeignService.getMessageCount();
        vo.setMessageCount(messageCount);
        return vo;
    }
}
